package com.changgou.test.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SynchornizedController {


    public static void main(String[] args) {
        te2 te2 = new te2();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {

            }
            te2.insert();
        }).start();

        new Thread(() -> {
            te2.del();
        }).start();

    }



}
class te2 {

    private int num =0;

    public void insert (){

        Lock lock = new ReentrantLock();
        Condition condition = lock.newCondition();
        Condition condition2 = lock.newCondition();
        Condition condition3 = lock.newCondition();
        lock.lock();
        try {
        while (num == 0) {
            condition.await();
            TimeUnit.SECONDS.sleep(1);
        }
            condition2.signal();
        } catch (Exception e) {
            System.out.println(e);
        } finally {
            lock.unlock();
        }
        System.out.println("添加！");
    }

    public void uodate (){
        System.out.println("添加！");
    }

    public void del (){
        System.out.println("添加！");
    }

}